package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.activity.LindiActivityQueryVO;
import com.minimalist.common.entity.lindi.vo.activity.LindiActivityVO;
import com.minimalist.common.feign.client.lindi.LindiActivityFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_活动管理")
@RequestMapping("/basic/lindi/activity")
public class LindiActivityController{

    @Autowired
    private LindiActivityFeignClient feignClient;

    @PostMapping("/addActivity")
    @SaCheckPermission("lindi:activity:add")
    @Operation(summary = "添加活动")
    public R<?> addActivity(
            @RequestBody @Validated(Add.class) LindiActivityVO activityVO){
        activityVO.setCreateId(StpUtil.getLoginIdAsLong());
        activityVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        activityVO.setCreateTime(now);
        activityVO.setUpdateTime(now);
        return feignClient.addActivity(activityVO);
    }

    @DeleteMapping("/deleteActivityByActivityId")
    @SaCheckPermission("lindi:activity:delete")
    @Operation(summary = "删除活动 -> 根据活动ID删除")
    public R<?> deleteActivityByActivityId(
            @RequestParam("ActivityId")
            @NotNull(message = "活动ID不能为空")
            @Parameter(name = "ActivityId", required = true
                    , description = "活动ID") Long activityId){
        return feignClient.deleteActivityByActivityId(activityId);
    }

    @PutMapping("/updateActivityByActivityId")
    @SaCheckPermission("lindi:activity:update")
    @Operation(summary = "修改活动")
    public R<?> updateActivityByActivityId(
            @RequestBody @Validated(Update.class) LindiActivityVO activityVO){
        activityVO.setCreateId(StpUtil.getLoginIdAsLong());
        activityVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        activityVO.setCreateTime(now);
        activityVO.setUpdateTime(now);
        return feignClient.updateActivityByActivityId(activityVO);
    }

    @GetMapping("/getPageActivityList")
    @SaCheckPermission("lindi:activity:get")
    @Operation(summary = "查询活动列表(分页)")
    public R<PageResp<LindiActivityVO>> getPageActivityList(LindiActivityQueryVO queryVO){
        System.out.println("queryVO = " + queryVO);
        System.out.println("feignClient.getPageActivityList(queryVO) = " + feignClient.getPageActivityList(queryVO));
        return feignClient.getPageActivityList(queryVO);
    }

    @GetMapping("/getActivityByActivityId/{ActivityId}")
    @SaCheckPermission("lindi:activity:get")
    @Operation(summary = "根据活动ID查询活动")
    public R<LindiActivityVO> getActivityByActivityId(
            @PathVariable(value = "ActivityId")
            @NotNull(message = "活动ID不能为空")
            @Parameter(name = "ActivityId", description = "参数ID"
                    , required = true) Long activityId){
        return feignClient.getActivityByActivityId(activityId);
    }
}